//
//  NetworkHelper.h
//  FlowerField
//
//  Created by 郑佳 on 2017/8/20.
//  Copyright © 2017年 Triangle. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZZNetWorkDecode.h"
#import "ZZNetWorkRequest.h"
#import "ZZNetWorkUploadRequest.h"
#import "ZZNetWorkResponse.h"
#import "ZZNetWorkParamHandler.h"
#import "ZZStreamTextResponseSerializer.h"

typedef void(^ZZNetWorkerDefaultBlock)(AFHTTPSessionManager *manager, ZZNetWorkRequest *request);
typedef void(^ZZNetWorkerManagerBlock)(AFHTTPSessionManager *manager);

@interface ZZNetWorker : NSObject

@property (nonatomic, strong) NSString *baseUrl;

/// 登录后获取的token
@property (nonatomic, strong) NSString *token;
@property (nonatomic, strong) NSString *tokenKey;

/// 设置请求接收结果的类 ，可替换 ，需继承  ZZNetWorkBaseResponse。
@property (nonatomic, strong) Class responseClass;
/// 发起请求前对入参的处理，可替换，需继承 ZZNetWorkParamHandler
@property (nonatomic, strong) ZZNetWorkParamHandler *paramHandler;
/// 网络请求返回数据通用解码，可替换，需继承 ZZNetWorkDecode
@property (nonatomic, strong) ZZNetWorkDecode *decode;

@property (nonatomic, strong) AFHTTPSessionManager *manager;
/**
  设置manager，只会调用一次，用于设置 AFHTTPSessionManager 初始配置。
 */
@property (nonatomic, strong, readonly) ZZNetWorker * (^zz_manager)(ZZNetWorkerManagerBlock block);
/**
 发起请求前会调用, 每次都会调用。设置ZZNetWorkRequest、AFHTTPSessionManager；
 */
@property (nonatomic, strong, readonly) ZZNetWorker * (^zz_defaultRequest)(ZZNetWorkerDefaultBlock block);

//AF设置
@property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * defaultRequestSerializer;
//AF设置
@property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * defaultResponseSerializer;

+ (ZZNetWorkRequest *)POST;
+ (ZZNetWorkRequest *)GET;
+ (ZZNetWorkUploadRequest *)UPLOAD;
+ (ZZNetWorkRequest *)DELETE;
+ (ZZNetWorkRequest *)PUT;

/**
 获取单例对象
 @return ZZNetWorker.new
 */
+ (ZZNetWorker *)woker;

- (NSURLSessionDataTask *)request:(ZZNetWorkRequest *)request;

@end
